﻿<DemoContainer>

    <Button OnClick=RenderChart BackgroundColor="TablerColor.Primary">Render</Button>

    <ApexChart @ref=chart TItem="Order"
               Title="@title">

        <ApexPointSeries TItem="Order"
                         Items="orders"
                         Name="Gross Value"
                         SeriesType="SeriesType.Bar"
                         XValue="@(e => e.Country)"
                         YAggregate="@(e => e.Sum(e => e.GrossValue))"
                         OrderByDescending="e=>e.Y" />

                 <ApexPointSeries TItem="Order"
                         Items="orders"
                         Name="Net Value"
                         SeriesType="SeriesType.Bar"
                         XValue="@(e => e.Country)"
                         YAggregate="@(e => e.Sum(e => e.NetValue))"
                         OrderByDescending="e=>e.Y" />
  

    </ApexChart>
</DemoContainer>

@code {
    private ApexChart<Order> chart;
    private List<Order> orders = SampleData.GetOrders();
    private string title = "Orders";
    private int counter = 1;

    private async Task RenderChart()
    {
        var rnd = new Random();
        foreach (var order in orders)
        {
            var multiply = rnd.NextDouble() + 0.5;
            order.GrossValue = Math.Round(order.GrossValue * (decimal)multiply);
        }

        title = $"Render[{counter}]";
        counter++;
        await chart.RenderAsync();
    }
}